<?php

namespace hec\core;

use app\library\facade\Config;
use GuzzleHttp\Client;
use GuzzleHttp\Middleware;

class Applets
{
    private $domain;

    public function __construct()
    {
        $this->domain = Config::get('hec.domain');
    }

    /**
     * 获取门店地址
     *
     * @param $data
     * @return bool|string
     */
    public function getStoreList($data)
    {
        $url = $this->domain . '/hec/v1/applets/getStoreList';

        return $this->postUrl($url, $data);
    }

    /**
     * 查询电子发票
     *
     * @param $data
     * @return \Psr\Http\Message\StreamInterface
     */
    public function getInvoiceList($data)
    {

        $url = $this->domain . '/hec/v1/applets/getInvoiceList';

        return $this->postUrl($url, $data);
    }

    private function postUrl($url, $data)
    {
        $client = new Client();
        $response = $client->post($url, [
            'json' => $data,
            'headers' => (new Signature())->generateHeader($data),
        ]);
        return json_decode($response->getBody()->getContents(), true);
    }
}